package org.example;

public class Test1 {
    //leetcode 392 判断子序列 https://leetcode.cn/problems/is-subsequence/description/
    public boolean isSubsequence(String s, String t) {
        char[] arr1 = s.toCharArray(),arr2 = t.toCharArray();
        int n1 = arr1.length, n2 = arr2.length;
        int[][] dp = new int[n1+1][n2+1];
        for (int i = 1; i <= n1; i++) {
            for (int j = 1; j <= n2; j++) {
                if (arr1[i-1] == arr2[j-1]) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                }else {
                    //删除t[j-1]之后的最长公共子序列
                    dp[i][j] = dp[i][j-1];
                }
            }
        }
        return dp[n1][n2] == n1;
    }
}
